package leetcode_301_400;

import node.TreeNode;

public class LeeCode_337 {
    public static void main(String[] args) {

    }
    private static int rob(TreeNode root) {
        int[] p = dfs(root);
        return Math.max(p[0], p[1]);
    }
    private static int[] dfs(TreeNode node){
        if (node == null){
            return new int[]{0,0};
        }
        int[] pl = dfs(node.left);
        int[] pr = dfs(node.right);
        int[] dp = new int[2];
        dp[0] = Math.max(pl[0], pl[1]) + Math.max(pr[0], pr[1]);
        dp[1] = node.val + pl[0] + pr[0];
        return dp;
    }
}
